package com.example.xxljobdemo.job;

import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

/**
 * @Description 测试
 * @Author wzh
 * @Date 2021/12/16 10:16 上午
 * @Version 1.0
 */
@Component
public class TestHandler {
    /**
     * 1、简单任务示例（Bean模式）
     */
    @XxlJob("demoJobHandler")
    public void demoJobHandler() throws Exception {
        XxlJobHelper.log("XXL-JOB, demo job hello.");
        String jobParam = XxlJobHelper.getJobParam();
        if(StringUtils.isNotEmpty(jobParam)){
            XxlJobHelper.log("参数:{}",jobParam);
        }

        for (int i = 0; i < 5; i++) {
            XxlJobHelper.log("beat at:" + i);
            TimeUnit.SECONDS.sleep(10);
        }
        // default success
    }


    @XxlJob("testJobHandler")
    public void testJobHandler() throws Exception {
        XxlJobHelper.log("XXL-JOB, test job hello.");

        for (int i = 0; i < 5; i++) {
            XxlJobHelper.log("test beat at:" + i);
            TimeUnit.SECONDS.sleep(10);
        }
        // default success
    }

}
